package com.example.hehecat.yuejian1.mvp.presenter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

import com.example.hehecat.yuejian1.mvp.contract.RegisterContract;
import com.example.hehecat.yuejian1.mvp.model.RegisterModel;
import com.example.hehecat.yuejian1.mvp.model.bean.SuccessBean;
import com.example.hehecat.yuejian1.mvp.model.bean.UserBean;
import com.example.hehecat.yuejian1.ui.wiget.MyStaticVariable;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class RegisterPresenter implements RegisterContract.Presenter {
    private RegisterContract.Model model;
    private RegisterContract.View view;

    public RegisterPresenter(RegisterContract.View view){
        this.view = view;
    }

    @Override
    public void register(String username, String password, String address, String phone) {
        model = new RegisterModel();
        model.register(username, password, address, phone, new Callback<UserBean>() {
            @Override
            public void onResponse(@NonNull Call<UserBean> call, @NonNull Response<UserBean> response) {
                if (!response.body().getUserid().equals("-1")) {
                    view.showdata("注册成功");
                    view.moveToLoginView();
                }
            }

            @Override
            public void onFailure(Call<UserBean> call, Throwable t) {
                    view.showdata(t.getMessage());
            }
        });
    }



}
